package org.springframework.liukai.test.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author liukai
 * @date 2022/7/19 13:04
 */
// @Component
public class MyBeanDefinitionRegistryPostProcessor1 implements BeanDefinitionRegistryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		Map<String, Object> beansWithAnnotation = beanFactory.getBeansWithAnnotation(MyAutoDiscovery.class);
		beansWithAnnotation.forEach((k, v) -> System.out.println(k + ":" + v.toString()));
	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		RootBeanDefinition rbd = new RootBeanDefinition(Person.class);
		registry.registerBeanDefinition("person111", rbd);
	}
}
